package com.itheima.service;

import com.itheima.mapper.UserMapper;
import com.itheima.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author zhouwei
 * @date 2020-01-13 11:11
 */
@Service
public class UserService {

    private UserMapper userMapper;
    //更据id查询user

    public User findByid(Long id){
        User user = userMapper.selectByPrimaryKey(id);
        return user;
    }

    //保存user
    @Transactional
    public void keep(User user){
        //选择性添加user，如果属性为空就不添加，属性为null
        userMapper.insertSelective(user);
        System.out.println("已保存");
    }

}
